<template>
	<view class="content">
		<musichead title="网易云音乐" :icon="false"></musichead>
		<view class="container">
			<!-- 滚动区域  scroll-y="true" 开启纵向滑动 -->
			<scroll-view scroll-y="true">
				<!-- 搜索框区域 -->
				<view class="index-search">
					<!-- 放大镜 -->
					<text class="iconfont">&#xe6e4;</text>
					<!-- 输入框 -->
					<input type="text" placeholder="搜索歌曲" />
				</view>
				<!-- 榜单列表区域 -->
				<view class="index-list">
					<!-- 每个榜单区域 -->
					<view class="index-list-item" v-for="(item,index) in topList" :key="index" @tap="handleToList(item.id)">
						<!--  左侧图片区域 -->
						<view class="index-list-img">
							<image :src="item.coverImgUrl"></image>
							<text>{{item.updateFrequency}}</text>
						</view>
						<!-- 右侧榜单歌曲列表 -->
						<view class="index-list-text">
							<view v-for="(item,index) in item.tracks" :key="index">
								{{index+1}}.{{item.first}}&nbsp;-&nbsp;{{item.second}}
							</view>
						
						</view>
					</view>
					
					
				</view>
				
				
			</scroll-view>
			
		</view>
	</view>
</template>

<script>
	//引入图标字体
	import '@/common/iconfont.css'
	//引入头部组件
	import musichead from '../../components/music-head/music-head.vue'
	//引入请求
	import { topList } from '../../common/api.js'
	export default {
		data() {
			return {
				title: 'Hello',
				//本地歌曲榜单变量
				topList:[]
			}
		},
		//生命周期函数 ，页面一加载就会调用
		onLoad() {
			topList().then((res)=>{
				//console.log(res)
				if(res.length){
					//给本地变量赋值
					this.topList=res;
				}
			})
		},
		
		//注册组件
		components:{
			musichead
		},
	
		methods: {
			//跳转到list页面,并携带榜单id
			handleToList(id){
				//console.log(id)
				uni.navigateTo({
					url: '/pages/list/list?id='+id
				});
			}
		}
	}
</script>

<style>
	/* 搜索框的样式 */
	.index{}
	.index-search{display: flex;align-items: center;height: 70rpx;margin:
	70rpx 30rpx 30rpx 30rpx;background: #F7F7F7;border-radius: 50rpx;}
	.index-search text{font-size: 26rpx;margin-right: 26rpx;margin-left:
	28rpx;}
	.index-search input{font-size: 28rpx;flex: 1;}
	/* 音乐分类样式 */
	.index-list{margin: 0 30rpx;}
	.index-list-item{display: flex;margin-bottom: 34rpx;}
	.index-list-img{width: 212rpx;height: 212rpx;position: relative;border-radius:
	30rpx;overflow: hidden;margin-right: 22rpx;}
	.index-list-img image{width: 100%;height: 100%;}
	.index-list-img text{position: absolute;left: 12rpx;bottom: 16rpx;color:
	white;font-size: 20rpx;}
	.index-list-text{font-size: 24rpx;line-height: 66rpx;}
	
</style>
